<?php

/*
	info: 更改用户信息
*/

define('IS_MEMBER_CHECK', TRUE);
require '../common.inc.php';

global_CheckPost(
	array(
		array('truename,','str','',$weblang['api_userTruenameError'],1),
		array('email,','email','',$weblang['api_userEmailError'],1),
		array('password','str','','',0,''),
		array('mobile,','str','',$weblang['api_userMobileError'],1),
		array('weddingdate','str','global_ConvTime(@)>0',$weblang['api_userWeddingdateError'],1),
));

if (!empty($webglobal['CPM']))
{
	$return['code'] = 1;
	$return['msg'] = reset($webglobal['CPM']);
	api_EchoReturn();
}

$webglobal['datainfo'] = $db->GetOne("SELECT * FROM user WHERE uid!='{$user['m_uid']}' AND (email='{$webglobal['CPP']['email']}' OR mobile='{$webglobal['CPP']['mobile']}')");
if (!empty($webglobal['datainfo']))
{
	if ($webglobal['datainfo']['email']==$webglobal['CPP']['email'])
	{
		$return['code'] = 1;
		$return['msg'] = $weblang['api_userEmailExists'];
		api_EchoReturn();
	}
	if ($webglobal['datainfo']['mobile']==$webglobal['CPP']['mobile'])
	{
		$return['code'] = 1;
		$return['msg'] = $weblang['api_userMobileExists'];
		api_EchoReturn();
	}
}

if ($webglobal['CPP']['password']!='')
{
	$webglobal['CPD']['password'] = md5($webglobal['CPP']['password']);
}
$webglobal['CPD']['weddingdate'] = global_ConvTime($webglobal['CPP']['weddingdate']);
$webglobal['CPD']['edittime'] = $webserver['timestamp'];
$db->Update('user', '', "uid='{$user['m_uid']}'");

$return['code'] = 0;
$return['data']['member'] = array(
	'uid' => $user['m_uid'],
	'truename' => $webglobal['CPD']['truename'],
	'email' => $webglobal['CPD']['email'],
	'mobile' => $webglobal['CPD']['mobile'],
	'weddingdate' => global_FormatTime($webglobal['CPD']['weddingdate'], $webglobal['weddingdatemode']),
);

if (!isset($webglobal['CPD']['password']))
{
	$webglobal['CPD']['password'] = $user['m_password'];
}
$objmem->SetUserCookie($webglobal['CPP']['email'], $webglobal['CPD']['password'], $webglobal['loginintime']);
api_EchoReturn();
